#include "LightPresetPlaybar.h"
#include "ui_LightPresetPlaybar.h"
#include "ApplicationIcon.h"

#include "qmessagebox.h"


LightPresetPlaybar::LightPresetPlaybar(QWidget *parent) :
   QGroupBox(parent),
   ui(new Ui::LightPresetPlaybar)
{
   ui->setupUi(this);
   m_levelView = ui->levelWidget;

   Q_ASSERT( m_levelView != NULL);

   /* setup icons */
   ui->playButton->setIcon( QIcon(IconPath("track_play.png")) );
   ui->deleteButton->setIcon( QIcon(IconPath("delete.png")) );
   ui->editButton->setIcon( QIcon(IconPath("edit.png")) );
}

LightPresetPlaybar::~LightPresetPlaybar()
{
   delete ui;
}


/**
 * @brief to be called to notify preset value changed. Used to draw level bars.
 * @param levels - list of light values in percent, range [0-100]
 */
void LightPresetPlaybar::setValueList(const QList<double> &levels)
{
   m_levelView->setLevelValues( levels);
}

void LightPresetPlaybar::on_playButton_clicked()
{
    emit play();
}

void LightPresetPlaybar::on_editButton_clicked()
{
    emit edit();
}

void LightPresetPlaybar::on_deleteButton_clicked()
{
   int answer;

   answer = QMessageBox::question( this, tr("confirm preset deletion"),
                                   tr("Are you sure to delete the preset ?"),
                                   QMessageBox::Yes, QMessageBox::No );

   if (answer == QMessageBox::Yes)
   {
      emit remove();
   }
}
